<?php
declare(strict_types=1);
namespace cms\wechat\queue;

use cms\wechat\service\OfficialService;
use cms\wechat\service\UserService;
use Hyperf\AsyncQueue\Job;

class MessageJob extends Job
{
    public array $params;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
        // 公众号服务实例
        $officialService = make(OfficialService::class);
        // 查询公众号
        $official = $officialService->model->where([
            ['original_id', '=', $this->params['ToUserName']]
        ])->first();
        // 用户服务实例
        $userService = make(UserService::class);
        // 同步用户
        $user = $userService->syncDataByServer($official, $this->params['FromUserName'], 0);
        switch ($this->params['MsgType']) {
            case 'event':
                switch ($this->params['Event']) {
                    case 'subscribe':  //关注事件

                        break;
                    case 'unsubscribe':  //取消关注

                        break;
                    case 'LOCATION':  //上报位置
                        break;
                    case 'CLICK':  //用户事件
                        break;
                    case 'SCAN': // 扫码
                        break;
                    default:  // 默认
                        break;
                }
                break;
            case 'text':
                break;
            case 'image':
                break;
            case 'voice':
                break;
            case 'video':
                break;
            case 'location':
                break;
            case 'link':
                break;
            default:
                break;
        }
    }
}